<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.12.4.js"></script>
</head>
<body>
<script type="text/javascript">
        	$(function() {
        		$("#begin").hide();
				$("#putnum").click(function() {
					var email=$("#newemail").val();
					var part=/^\d{5,12}@[qQ][qQ]\.(com|cn)$/;
					if(email==null||email==""){
						$("#error2").html("请输入邮箱后再发送验证码");
					}else if(!part.test(email)){
						$("#error2").html("邮箱格式不正确");
					}else if(part.test(email)){
						$.get("${pageContext.request.contextPath}/users/ishaveemail",
								{"email":email},
								function(data) {
									if(data==null){
										$("#error2").html("经检测此邮箱还未注册");
									}else{
										$("#error2").html("");
										$.get("${pageContext.request.contextPath}/users/ajaxemail",
												{"email":email},
												function(data) {
													$("#error2").html("请查看手机邮箱，填写验证码");
													$("#data").val(data);
												})
									}
								})
						
					}	
				})
				$("#updateemaill").click(function() {
					var a=$("#yanzhengma").val();
					var data=$("#data").val();
					var email=$("#newemail").val();
					if(a==null||a==""){
						$("#error2").html("请输入验证码！");
					}else if(a!=data){
						$("#error2").html("验证码不正确！");
					}else{
						alert("验证通过");
						$.get("${pageContext.request.contextPath}/users/queryUserid",
								{"email":email},
								function(data) {
									$("#userid").val(data.userid);
								})
						$("#begin").show();
						$("#hiddenemail").hide();
					}
				})
			})
		</script>
<script type="text/JavaScript">
							$(function() {
								var tishi="${message}";
								if(tishi!=null&&tishi!=""){
									if(confirm("修改成功，快去登录吧！")){
										location.href="${pageContext.request.contextPath}/users/tologin";
									}
								}
								var password="${users.password}";
								
								$("#newpassword").blur(function() {
									var newpassword=$("#newpassword").val();
									var pattr=/^[a-zA-Z]\w{5,17}$/;
									if(newpassword==null||newpassword==""){
										$("#error").text("新密码不能为空");
									}else if(!pattr.test(newpassword)){
										$("#error").text("新密码格式不正确");
									}else{
										$("#error").text("");
									}
								})
								$("#passwordform").submit(function() {
									
									var newpassword=$("#newpassword").val();
									var pattr=/^[a-zA-Z]\w{5,17}$/;
									if(newpassword==null||newpassword==""){
										$("#error").text("新密码不能为空");
										return false;
									}else if(!pattr.test(newpassword)){
										$("#error").text("新密码格式不正确");
										return false;
									}
									var renewpassword=$("#renewpassword").val();
									if(renewpassword==null||renewpassword==""){
										$("#error").text("重复密码不能为空！");
										return false;
									}else if(renewpassword!=newpassword){
										$("#error").text("重复密码不正确！");
										return false;
									}
								})
							})
						</script>
<div style="position: relative;left: 40%;;top: 65px; width: 372px; height:554px; background-color: white; border-radius: 10%; ">
	
		<div id="hiddenemail" style="width: 231px;">
		<p>第一步：邮箱验证</p>
						<br />
							<form id="updateemail" action="#" method="post">
							<input type="hidden" id="data" value=""/>
							<p>&nbsp;&nbsp;&nbsp;邮箱：<input type="text" id="newemail" name="email" value="" style="height: 34px;"/></p>
							<p>验证码：<input type="text" id="yanzhengma" style="width: 62px;height: 34px;"/>&nbsp;&nbsp;&nbsp;<input type="button" id="putnum" style="background-color:#319DE5;width: 86px;height:40px; color: white;border: none;outline:none;" value="获取验证码" /></p>
							<p><span id="error2" style="color: red"></span><input type="button" id="updateemaill" style="background-color:#319DE5;width: 238px;height:40px; border-radius:50px;color: white;border: none;outline:none;"value="开始验证"/></p>
							</form>
		</div>
		<div id="begin" style="width: 231px;">
		<p>第二步：修改密码</p>
		<form id="passwordform" target="_top" method="post" action="${pageContext.request.contextPath}/users/updatepasswordsucess">
							<input type="hidden" id="userid" name="userid" value="" />
							<p>请填写新密码：<input type="password" style="height: 34px" id="newpassword" name="password" value=""/></p>
							<p>请重复新密码：<input type="password" style="height: 34px" id="renewpassword" name="renewpassword" value=""/></p>
							<p><span id="error" style="color: red"></span><input type="submit"  id="updatepassword" class="btn btn-mystyle btn-sm" style="background-color:#319DE5;width: 238px;height:40px; border-radius:50px;color: white;border: none;outline:none;" value="确认修改"/></p>
							</form>
		</div>
	
</div>	
</body>
</html>